<script setup lang="ts">
import { ref } from 'vue'
import adminNav from '@/components/admin/adminNavbar-left.vue'
import { Menu as IconMenu } from '@element-plus/icons-vue'

// 控制移动端抽屉菜单的显示
const drawerVisible = ref(false)
</script>

<template>
  <div class="admin-layout">
    <aside class="admin-sidebar">
      <admin-nav />
    </aside>

    <el-drawer
      v-model="drawerVisible"
      title="后台导航"
      direction="ltr"
      size="240px"
      :with-header="false"
      class="admin-drawer"
    >
      <admin-nav @menu-select="drawerVisible = false" />
    </el-drawer>

    <main class="admin-main-content">
      <header class="admin-header-mobile">
        <span class="header-title">后台管理</span>
        <el-icon class="hamburger-icon" :size="24" @click="drawerVisible = true">
          <IconMenu />
        </el-icon>
      </header>

      <div class="admin-content-card">
        <router-view />
      </div>
    </main>
  </div>
</template>
<style scoped>
/* --- 全局布局 --- */
.admin-layout {
  display: flex;
  min-height: 100vh;
  background-color: #f4f7fa; /* 更柔和的背景色 */
}

/* --- 侧边栏 (桌面) --- */
.admin-sidebar {
  width: 220px;
  flex-shrink: 0;
  background-color: #ffffff;
  border-right: 1px solid #e9ecef;
  transition: width 0.3s;
}

/* --- 主内容区 --- */
.admin-main-content {
  flex-grow: 1;
  padding: 24px;
  overflow-x: hidden; /* 防止内容溢出 */
  display: flex;
  flex-direction: column;
}

.admin-content-card {
  flex-grow: 1;
  padding: 24px;
  background-color: #ffffff;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

/* --- 移动端适配 --- */
.admin-header-mobile {
  display: none; /* 默认隐藏 */
}

@media (max-width: 768px) {
  .admin-sidebar {
    display: none; /* 移动端隐藏侧边栏 */
  }

  .admin-main-content {
    padding: 16px; /* 移动端减小内边距 */
  }

  .admin-content-card {
    padding: 16px;
  }

  .admin-header-mobile {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    height: 60px;
    background-color: #ffffff;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    margin-bottom: 16px;
  }

  .header-title {
    font-size: 1.1rem;
    font-weight: 600;
  }

  .hamburger-icon {
    cursor: pointer;
  }
}
</style>
